package com.sale.table.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.table.domain.dto.PurchasePaymentDto;
import com.sale.table.domain.vo.PurchasePaymentVo;
import com.sale.table.mapper.PurchasePaymentMapper;
import com.sale.table.service.PurchasePaymentService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 采购付款一览表 实现层
 */
@RequiredArgsConstructor
@Service
public class PurchasePaymentServiceImpl implements PurchasePaymentService {

    private final PurchasePaymentMapper purchasePaymentMapper;

    /**
     * 采购付款一览表列表
     */
    @Override
    public TableDataInfo<PurchasePaymentDto> purchasePaymentList(PurchasePaymentVo purchasePaymentVo, PageQuery pageQuery) {
        List<PurchasePaymentDto> resultList = new ArrayList<>();
        //采购入库数据
        List<PurchasePaymentDto> purchasePaymentList = purchasePaymentMapper.getPurchasePaymentList(purchasePaymentVo);
        //采购退货数据
        List<PurchasePaymentDto> pickingPurchaseList = purchasePaymentMapper.getPickingPurchaseList(purchasePaymentVo);
        resultList.addAll(purchasePaymentList);
        resultList.addAll(pickingPurchaseList);

        Page<PurchasePaymentDto> page = new Page<>();
        List<PurchasePaymentDto> collect = resultList.stream().skip((long) (pageQuery.getPageNum() - 1) * pageQuery.getPageSize()).limit(pageQuery.getPageSize()).collect(Collectors.toList());
        page.setRecords(collect);
        page.setTotal(resultList.size());
        return TableDataInfo.build(page);
    }
}
